<?php

	class school_year extends spModel{

		var $pk = "id"; // 每个留言唯一的标志，可以称为主键

		var $table = "school_year"; // 数据表的名称

		

		var $validator = array(

			"rules" => array(

				'name' => array(

					'required' => true,

					'minlength' => 2,

					'maxlength' => 20

				),

		

			),

			"messages" => array(

				'name' => array(

					'required' => '学年名称不能为空',

					'minlength' => '学年名称请在2~20位字符之间',

					'maxlength' => '学年名称请在2~20位字符之间'

				),

			)

		);

		

		public function checkEndtime($starttime, $endtime){

			if($endtime <= $starttime){

				return false;

			}else{

				return true;

			}

		}

	

		public function setStatus($starttime, $endtime){

			if($starttime < time() && $endtime < time()){

				$status = 2;

			}

			if($starttime > time()  && $endtime > time()){

				$status = 0;

			}

			if($starttime < time()  && $endtime > time()){

				$status = 1;

			}

			return $status;

		}



		public function checkNextStarttime($starttime,$id=0){

            if($id > 0){
                //修改验证
                $lastEndTime = $this ->find(array('isdel'=>0,'id <>' =>$id),'endtime desc');
            }else{
                //增加验证
                $lastEndTime = $this ->find(array('isdel'=>0),'endtime desc');
            }
            if($lastEndTime && strtotime($lastEndTime['endtime']) >= $starttime){
                return false;
            }else{
                return true;
            }

		}

	}

?>